home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Found / FWExcLib / Include / FWExcDef.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-08  |  6.9 KB  |  301 lines  |  [TEXT/MPS ]

  1. #ifndef FWEXCDEF_H
  2. #define FWEXCDEF_H
  3. //========================================================================================
  4. //
  5. //    File:                FWExcDef.h
  6. //    Release Version:    $ 1.0d11 $
  7. //
  8. //    Copyright:    (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef FWENVDEF_H
  13. #include "FWEnvDef.h"
  14. #endif
  15.  
  16. #ifndef   FWONSTAC_H
  17. #include "FWOnStac.h"
  18. #endif
  19.  
  20. #ifndef   FWCLAINF_H
  21. #include "FWClaInf.h"
  22. #endif
  23.  
  24. #ifndef   FWEXCEPT_H
  25. #include "FWExcept.h"
  26. #endif
  27.  
  28. #ifndef   FWTRYBLO_H
  29. #include "FWTryBlo.h"
  30. #endif
  31.  
  32. #ifndef   FWEXCRUN_H
  33. #include "FWExcRun.h"
  34. #endif
  35.  
  36. #ifndef   FWDELSTA_H
  37. #include "FWDelSta.h"
  38. #endif
  39.  
  40. #if FW_LIB_EXPORT_PRAGMAS
  41. #pragma lib_export on
  42. #endif
  43.  
  44. #ifdef FW_BAD_CODE_GENERATION
  45. int ReturnFalse();
  46. int ReturnTrue();
  47. #define FW_BEL_FALSE ::ReturnFalse()
  48. #define FW_BEL_TRUE ::ReturnTrue()
  49. #else
  50. #define FW_BEL_FALSE 0
  51. #define FW_BEL_TRUE 1
  52. #endif
  53.  
  54. //========================================================================================
  55. // Exception Handling Interface Macros
  56. //========================================================================================
  57.  
  58. #define FW_VOLATILE(a) ((void) &a)
  59.  
  60. #ifdef FW_NATIVE_EXCEPTIONS
  61.  
  62. // --------------- Native exceptions
  63.  
  64.     #define FW_TRY \
  65.         try
  66.  
  67.     #define FW_CATCH_BEGIN
  68.     
  69.     #define FW_CATCH(class, error) \
  70.         catch(class error)
  71.  
  72.     #define FW_CATCH_REFERENCE(class, error) \
  73.         catch(class& error)
  74.                     
  75.     #define FW_CATCH_NO_INSTANCE(class)    \
  76.         catch(class)
  77.  
  78.     #define FW_CATCH_EVERYTHING()    \
  79.         catch(...)
  80.  
  81.     #define FW_CATCH_END
  82.  
  83.     #define FW_THROW(error)             throw error
  84.     #define FW_THROW_SAME()                throw
  85.     #define FW_THROWS_NOTHING()            // we don't support this in emulation anyhow...
  86.     #define FW_THROWS(class)            // we don't support this in emulation anyhow...
  87.  
  88.     #define FW_END_CONSTRUCTOR
  89.     #define FW_START_DESTRUCTOR
  90.     #define FW_NEW(class, args)            new class##args
  91.     
  92.     #define FW_AUTO_DESTRUCT_OBJECT
  93.     #define FW_AUTO_DESTRUCT_MIXIN
  94.     #define FW_EXCEPTION_OBJECT
  95.  
  96. #elif !defined FW_DISABLE_EXCLIB
  97.  
  98. // --------------- Exception emulation library
  99.  
  100.  
  101. #ifdef FW_USE_NEW_HELPER
  102.  
  103. class FW_CPrivNewHelper;
  104.  
  105. #ifdef __MWERKS__
  106.  
  107. extern const FW_CPrivNewHelper& _FW_MetrowerksHack(const FW_CPrivNewHelper&);
  108.  
  109. #define FW_NEW(class, args) (class*)                                            \
  110.         (                                                                        \
  111.             (new(_FW_MetrowerksHack(FW_CPrivNewHelper(::operator new, ::operator delete))) class##args),     \
  112.             ((void*) FW_CPrivNewHelper::PopNewHelper()->ForgetObject())                \
  113.         )
  114.  
  115. #else
  116.  
  117. #define FW_NEW(class, args) (class*)                                            \
  118.         (                                                                        \
  119.             (new(FW_CPrivNewHelper(::operator new, ::operator delete)) class##args),     \
  120.             ((void*) FW_CPrivNewHelper::PopNewHelper()->ForgetObject())                \
  121.         )
  122. #endif
  123.  
  124. #else
  125. #define FW_NEW(class, args) new class##args
  126. #endif
  127.  
  128. #define FW_SAVE_TRACE_STATE 
  129. #define FW_RESTORE_TRACE_STATE 
  130.  
  131. #define FW_TRY \
  132.     { \
  133.         FW_SPrivExceptionGlobals& __excGlobals = FW_CExceptionTaskGlobals::GetExceptionGlobals(); \
  134.         FW_SAVE_TRACE_STATE \
  135.         jmp_buf    __jumpBuffer; \
  136.         if(setjmp(__jumpBuffer) == 0) \
  137.         { \
  138.             FW_CPrivTryBlockContext __context(__excGlobals, __jumpBuffer);
  139.  
  140. #define FW_CATCH_BEGIN \
  141.         } \
  142.         else \
  143.         { \
  144.             FW_RESTORE_TRACE_STATE \
  145.             if (FW_BEL_FALSE) \
  146.             {
  147.  
  148. #define FW_CATCH(class, error) \
  149.             } \
  150.             else if (__excGlobals.gThrownException->PrivIsKindOf(FW_CLASS_INFO_PTR(class))) \
  151.             { \
  152.                 class error = * (class*) __excGlobals.gThrownException; \
  153.                 FW_CPrivExceptionRuntime::CaughtException(__excGlobals, &error);
  154.  
  155. #define FW_CATCH_REFERENCE(class, error) \
  156.             } \
  157.             else if (__excGlobals.gThrownException->PrivIsKindOf(FW_CLASS_INFO_PTR(class))) \
  158.             { \
  159.                 class & error = *(class*) __excGlobals.gThrownException; \
  160.                 FW_CPrivExceptionRuntime::CaughtReferenceException(__excGlobals);
  161.  
  162. #define FW_CATCH_NO_INSTANCE(class) \
  163.             } \
  164.             else if (__excGlobals.gThrownException->PrivIsKindOf(FW_CLASS_INFO_PTR(class))) \
  165.             { \
  166.                 FW_CPrivExceptionRuntime::CaughtNoInstanceException(__excGlobals);
  167.  
  168. #define FW_CATCH_EVERYTHING() \
  169.             } \
  170.             else if (FW_BEL_TRUE) \
  171.             { \
  172.                 FW_CPrivExceptionRuntime::CaughtEverythingException(__excGlobals);
  173.  
  174. #define FW_CATCH_END \
  175.             } \
  176.             else \
  177.             { \
  178.                 FW_CPrivExceptionRuntime::KeepThrowing(__excGlobals); \
  179.             } \
  180.         FW_CPrivExceptionRuntime::CatchCleanup(__excGlobals); \
  181.         } \
  182.     }
  183.  
  184. #define FW_THROW(error) \
  185.     FW_CPrivExceptionRuntime::Throw(error)
  186.  
  187. #define FW_THROW_SAME() \
  188.     FW_CPrivExceptionRuntime::ThrowSame()
  189.  
  190. #define FW_THROWS_NOTHING() \
  191.     FW_CPrivThrowGuard __nothing
  192.  
  193. #define FW_THROWS(class) \
  194.     FW_CPrivThrowGuard __nothing##class(FW_CLASS_INFO_PTR(class))
  195.  
  196. #ifdef FW_USE_NEW_HELPER    
  197.     #define FW_END_CONSTRUCTOR    \
  198.         FW_CPrivExceptionRuntime::EndConstructor(this, sizeof(*this));
  199.     #define FW_START_DESTRUCTOR \
  200.         if (_FW_PrivIsOnStack(this)) \
  201.             FW_CPrivDeleteStack::PopIfTopEquals(this);
  202. #else
  203.     #define FW_END_CONSTRUCTOR \
  204.         if (_FW_PrivIsOnStack(this)) \
  205.             FW_CPrivDeleteStack::Push(this);
  206.     #define FW_START_DESTRUCTOR \
  207.         if (_FW_PrivIsOnStack(this)) \
  208.             FW_CPrivDeleteStack::PopIfTopEquals(this);
  209. #endif
  210.  
  211.     #define FW_AUTO_DESTRUCT_OBJECT : public _FW_CAutoDestructObject
  212.     #define FW_AUTO_DESTRUCT_MIXIN public _FW_CAutoDestructObject,
  213.     #define FW_EXCEPTION_OBJECT : public _FW_XException
  214.  
  215. #else
  216.  
  217. // --------------- Exceptions are turned off
  218.     
  219.     #define FW_TRY \
  220.     { \
  221.         if(FW_BEL_TRUE) \
  222.         {
  223.  
  224.     #define FW_CATCH_BEGIN \
  225.         } \
  226.         else \
  227.         { \
  228.             if (FW_BEL_FALSE) \
  229.             {
  230.     
  231.     #define FW_CATCH(class, error) \
  232.             } \
  233.             else if (FW_BEL_FALSE) \
  234.             { \
  235.                 class error = * (class*) 0;
  236.  
  237.     #define FW_CATCH_REFERENCE(class, error) \
  238.             } \
  239.             else if (FW_BEL_FALSE) \
  240.             { \
  241.                 class & error = *(class*) 0;
  242.                     
  243.     #define FW_CATCH_NO_INSTANCE(class) \
  244.             } \
  245.             else if (FW_BEL_FALSE) \
  246.             {
  247.  
  248.     #define FW_CATCH_EVERYTHING() \
  249.             } \
  250.             else if (FW_BEL_TRUE) \
  251.             {
  252.  
  253.     #define FW_CATCH_END \
  254.             } \
  255.             else \
  256.             { \
  257.             } \
  258.         } \
  259.     }
  260.  
  261.     #define FW_THROW(error) FW_DEBUG_MESSAGE(#error)
  262.     #define FW_THROW_SAME()
  263.     #define FW_THROWS_NOTHING()
  264.     #define FW_THROWS(class)
  265.  
  266.     #define FW_END_CONSTRUCTOR
  267.     #define FW_START_DESTRUCTOR
  268.     #define FW_NEW(class, args) new class##args
  269.  
  270.     #define FW_AUTO_DESTRUCT_OBJECT
  271.     #define FW_AUTO_DESTRUCT_MIXIN
  272.     #define FW_EXCEPTION_OBJECT
  273.  
  274. #endif
  275.  
  276. //========================================================================================
  277. // Exception Logging Macros
  278. //========================================================================================
  279.  
  280. #define FW_LOG_OR_TRIGGER_EXCEPTION(class, instance)
  281. #define FW_CAUSE_EXCEPTION_BY_NAME(name)
  282. #define FW_CAUSE_EXCEPTION_BY_COUNT(count)
  283.  
  284. //========================================================================================
  285. // Exception Testing Macros
  286. //========================================================================================
  287.  
  288. #ifdef FW_DEBUG
  289. #define FW_DECLARE_THROW_POINT(NAME) FW_CExceptionThrowPoint FW_g##NAME##ThrowPoint (#NAME)
  290. #define FW_CHECK_THROW_POINT(NAME)     FW_g##NAME##ThrowPoint.Check ()
  291. #else
  292. #define FW_DECLARE_THROW_POINT(NAME) 
  293. #define FW_CHECK_THROW_POINT(NAME)     
  294. #endif
  295.  
  296. #if FW_LIB_EXPORT_PRAGMAS
  297. #pragma lib_export off
  298. #endif
  299.  
  300. #endif
  301.